# -*- coding: utf-8 -*-
# -*- frozen_string_literal: true -*

<%= @scaffold.sublevel_require_minitest_config %>
require "<%= @scaffold.gem_path %>/manifest"

class Test<%= @scaffold.gem_namespace %>Manifest < Minitest::Test
parallelize_me!

def test_has_gem_name
assert_equal "<%= @scaffold.gem_name %>", <%= @scaffold.namespace %>::Manifest.gem_name
end

def test_has_official_name
assert_equal "<%= @scaffold.formatted_name %>", <%= @scaffold.namespace %>::Manifest.official_name
  end

  def test_has_authors
    expected_authors = ["<%= @scaffold.author %>"]
    authors = <%= @scaffold.namespace %>::Manifest.authors

    assert_equal expected_authors, authors
    assert_frozen authors
  end

  def test_has_contact_emails
    expected_emails = %w[<%= @scaffold.email %>]
    emails = <%= @scaffold.namespace %>::Manifest.contact_emails
    assert_equal expected_emails, emails
    assert_frozen emails
  end

  def test_has_repo
    assert_equal "<%= @scaffold.repo %>", <%= @scaffold.namespace %>::Manifest.repo
  end

  def test_has_license
    assert_equal "<%= @scaffold.license %>", <%= @scaffold.namespace %>::Manifest.license
  end

def test_has_metadata
# :TODO:
expected_metadata = {
"source_code_uri"   => "<%= @scaffold.repo %>",
"bug_tracker_uri"   => "https://example.com/USERNAME/<%= @scaffold.gem_name %>/issues",
"changelog_uri"     => "https://example.com/USERNAME/<%= @scaffold.gem_name %>/src/master/ChangeLog.md"
}

metadata = <%= @scaffold.namespace %>::Manifest.metadata

assert_equal expected_metadata, metadata
assert_frozen metadata
end

def test_has_files
expected_files = %w[
ChangeLog.md
Contribute.md
License.md
Manifest.md
Rakefile
ReadMe.md
Security.md
_expand_lib_path.rb
] +
Dir["bin/*"] +
Dir["{lib,test}/**/*.rb"] - Dir["test/dev/**/*rb"] # exclude dev helpers

# assert_frozen missing. Apparently Gem::Specification mutates it.
# must be unordered because CI
assert_equal_unordered expected_files, <%= @scaffold.namespace %>::Manifest.files
end

def test_codebase_returns_required_paths_basenames
    lib = "lib"
    codebase = <%= @scaffold.namespace %>::Manifest.codebase

      assert <%= @scaffold.namespace %>::Manifest.files.any? { |f| %r[\A#{lib}/(.*)].match? f }
    assert_equal [lib], codebase
    assert_frozen codebase
  end

  def test__test_suite_returns_test_dir_basename
    suite = "test"
    assert_equal suite, <%= @scaffold.namespace %>::Manifest.test_suite
      assert <%= @scaffold.namespace %>::Manifest.files.any? { |f| %r[\A#{suite}/(.*)].match? f }
  end

  def test__tests_are_included_in_the_manifest
    tests = <%= @scaffold.namespace %>::Manifest.tests
    files = <%= @scaffold.namespace %>::Manifest.files

    tests.each { |t| assert_includes files, t }
    assert_frozen tests
  end
  <% if @scaffold.bin %>

  def test_has_bindir
    assert_equal "bin", <%= @scaffold.namespace %>::Manifest.bindir
  end

  def test_binstubs_are_among_files_in_the_manifest
    binstubs = <%= @scaffold.namespace %>::Manifest.binstubs
    files = <%= @scaffold.namespace %>::Manifest.files
    bindir = <%= @scaffold.namespace %>::Manifest.bindir

    binstubs.each { |b| assert_includes files, "#{bindir}/#{b}" }
    assert_frozen binstubs
  end
  <% end %>
end
